package com.bzkj.web.controller.basicInfo.pick;

import com.bzkj.basicinfo.domain.pick.WmsPickTaskEntity;
import com.bzkj.basicinfo.service.pick.WmsPickTaskService;
import com.bzkj.common.annotation.LogB;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import com.bzkj.common.utils.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import static com.bzkj.common.core.page.TableSupport.PAGE_NUM;
import static com.bzkj.common.core.page.TableSupport.PAGE_SIZE;

@RestController
@RequestMapping("/wms/pick")
public class WmsPickTaskController extends BaseController {

    @Autowired
    private WmsPickTaskService pickTaskService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('wms:pick:list')")
    public TableDataInfo list(WmsPickTaskEntity entity) {
        Integer pageNum = ServletUtils.getParameterToInt(PAGE_NUM, 1);
        Integer pageSize = ServletUtils.getParameterToInt(PAGE_SIZE, 10);
        return pickTaskService.getPickTaskList(entity, pageNum, pageSize);
    }

    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('wms:pick:query')")
    public AjaxResult getDetail(@PathVariable("id") Long id) {
        return pickTaskService.getPickTaskDetail(id);
    }

    @PostMapping
    @PreAuthorize("@ss.hasPermi('wms:pick:add')")
    @LogB(title = "新增拣货任务", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody WmsPickTaskEntity entity) {
        return pickTaskService.createPickTask(entity, getUsername());
    }

    @PutMapping("/complete/{id}")
    @PreAuthorize("@ss.hasPermi('wms:pick:edit')")
    @LogB(title = "完成拣货任务", businessType = BusinessType.UPDATE)
    public AjaxResult complete(@PathVariable("id") Long id) {
        return pickTaskService.completeTask(id, getUsername());
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('wms:pick:remove')")
    @LogB(title = "删除拣货任务", businessType = BusinessType.DELETE)
    public AjaxResult remove(@PathVariable("id") Long id) {
        return pickTaskService.deletePickTask(id, getUsername());
    }
}
